<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/common.css" />
		<link rel="stylesheet" type="text/css" href="../css/chat-msg.css"/>
		<style type="text/css">
			html,
			body {
				height: 100%;
				margin: 0px;
				padding: 0px;
				overflow: hidden;
				-webkit-touch-callout: none;
				-webkit-user-select: none;
			}

			.mui-content {
				height: 100%;
				padding-top: 44px;
				overflow: auto;
			}
			
			#msg-list {
				height: 100%;
				overflow: auto;
				-webkit-overflow-scrolling: touch;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav bar-inverse">
			<a class="mui-action-back mui-icon mui-icon-back mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">消息记录</h1>
		</header>
		<div class="mui-content">
			<div id="msg-list"></div>
		</div>
		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/chatMsg.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/user.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var page = 1, msgInit = null;
			var msgList = document.getElementById("msg-list");
			mui.plusReady(function(data) {
				var self = plus.webview.currentWebview();
				console.log(self.sender);
				console.log(self.receiver);
				msgInit = {
					el: '#msg-list', //消息容器
					senderAvatar: Common.artistPic + User.getMyID() + User.getMyPic() + '?' + Math.random(), //发送者头像 (我的头像)
					receiverAvatar: Common.artistPic + self.receiver + self.pic + '?' + Math.random(), //接收者头像 (对方头像)
				}
				var url = baseURL + 'message/getListBySenderMui/token/' + self.sender + '/' + self.receiver + '/' + page + '/20.json';
				console.log(url);
				Common.ajax({
					url : url
				}, function(data) {
					console.log(JSON.stringify(data));
					console.log(data.code);
					if(data.code == 1) {
						var msglog = data.result;
						if(!msglog.length) {
							Common.showState(msgList, '&#xe62b;', '暂无消息记录', 50);
						} else {
							for (var i = 0; i < msglog.length; i++) {
								if(msglog[i].sender == 'self') {
									msgShow('sender', 'text', msglog[i].content);
								} else {
									msgShow('receiver', 'text', msglog[i].content);
								}
							}
							msgList.scrollTop = msgList.scrollHeight + msgList.offsetHeight;
						}
					} else {
						mui.toast('消息记录读取失败，请稍后重试');
					}
				}, function(xhr) {
					Common.linkError();
					console.error('failed - ' + xhr.status + ' : ' + xhr.statusText);
				})
			})
		</script>
	</body>

</html>